<template>
  <div>
    <page-main>
      <el-table :data="tableData" v-loading="loading" height="50vh">
        <el-table-column label="id" width="60" prop="id"></el-table-column>
        <el-table-column label="单位名称" prop="name"> </el-table-column>
        <el-table-column label="监管等级" prop="watch_level"> </el-table-column>
        <el-table-column label="单位地址" prop="address"> </el-table-column>
        <el-table-column label="行政区域" prop="region_name"> </el-table-column>
        <el-table-column label="单位类型" prop="unit_type"> </el-table-column>
        <el-table-column label="负责人" prop="contact_name" width="110">
        </el-table-column>
        <el-table-column label="联系电话" prop="phone"> </el-table-column>
        <el-table-column label="服务机构" prop="wb_name"> </el-table-column>
        <el-table-column
          label="创建时间"
          prop="add_time"
          sortable
          :formatter="formatDate"
          width="110"
        ></el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @current-change="getDataList"
          v-model:currentPage="tableDataInfo.page"
          :page-count="tableDataInfo.total_page"
          :total="tableDataInfo.total"
          background
          layout="total,prev, pager, next, jumper"
        >
          <!-- :hide-on-single-page="true" -->
        </el-pagination>
      </div>
    </page-main>
  </div>
</template>
<script>
export default {
  props: ["drillTrainType"],
  data() {
    return {
      tableData: [],
      loading: false,
      tableDataInfo: "",
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.getDataList();
    });
  },
  methods: {
    formatDate(row, column, time, index) {
      return this.$getDateTime(time);
    },
    getDataList(page) {
      let unit_id = localStorage.getItem('fa_user_info')
      let pageNum = 1;
      if (page) {
        pageNum = page;
      }
      this.loading = true;
      this.$api
        .post("/unit/Dashboard/dangerList", {
          type: this.drillTrainType,
          page: pageNum,
          rows: 10,
          unit_id:JSON.parse(unit_id).unit_id
        })
        .then((res) => {
          this.tableData = res.data.list;
          this.tableDataInfo = res.data;
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
};
</script>
<style scoped lang="scss">
.block {
    display: flex;
    justify-content: center;
}
.searchBox {
    margin: 20px;
    display: flex;
    background-color: #fff;
    padding: 20px;
    .input {
        width: 12%;
        margin-right: 15px;
    }
    .hint {
        line-height: 40px;
        margin-right: 10px;
    }
    .searchBtn {
        background-color: #2d8cf0;
        color: #fff;
    }
}
</style>
